Trò chơi 2D Cow Boy Runner

52.946 lượt xem;
1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4 using
UnityEngine.UI;
5
6 public
class Scores : MonoBehaviour {
7
8     
public static Scores instance;
9
10     
private const string BEST_SCORE = "bestScore";
11
12     
private const string BEST_COIN_SCORE = "bestCoinScore";
13
14     
// Use this for initialization
15     
void Awake () {
16         GameStartedFirstTime ();
17         MakeSingleton ();
18     }
19     
20     
// Update is called once per frame
21     
void Update () {
22
23     }
24
25     
void MakeSingleton () {
26         
if (instance != null) {
27             Destroy (gameObject);
28         }
else {
29             instance =
this;
30             DontDestroyOnLoad (gameObject);
31         }
32     }
33
34     
void GameStartedFirstTime() {
35         
if(!PlayerPrefs.HasKey ("isGameStartedFirstTime")) {
36             PlayerPrefs.SetInt (BEST_SCORE,
0);
37             PlayerPrefs.SetInt (BEST_COIN_SCORE,
0);
38             PlayerPrefs.SetInt (
"isGameStartedFirstTime", 0);
39
40         }
41     }
42
43     
public void SetHighScore (int score) {
44         PlayerPrefs.SetInt (BEST_SCORE, score);
45     }
46
47     
public int GetHighScore () {
48         
return PlayerPrefs.GetInt (BEST_SCORE);
49     }
50
51     
public void SetHighCoinScore (int highCoinScore) {
52         PlayerPrefs.SetInt (BEST_COIN_SCORE, highCoinScore);
53     }
54
55     
public int GetHighCoinScore () {
56         
return PlayerPrefs.GetInt (BEST_COIN_SCORE);
57     }
58 }


Use this for initialization

Update is called once per frame



Gõ tìm kiếm nhanh...